// @flow
import React from 'react';
import { connect } from 'react-redux';
import Qs from 'qs';
// import { sendCode } from 'lib/api/user';
import Storage, { keys } from 'lib/storage';
import FullSceenProgress from 'components/Base/FullSceenProgress';
import { AuthActions } from 'store/actionCreators';

type Props = {
    windowName: string,
    param: string
};
const RedirectContainer = ({ param, windowName }: Props) => {
    // console.log(param);
    const code = Qs.parse(param.substring(1, param.length)).code;
    console.log('code:' + code);
    // sendCode(windowName, SocailCode);
    let auth = {};
    auth = Storage.get(keys.auth) === null ? {} : Storage.get(keys.auth);
    //
    auth['code'] = code;
    Storage.set(keys.auth, auth);
    AuthActions.sendCodeRequest({ windowName: window.name, code: code });
    window.close();
    return <FullSceenProgress visible={true} />;
};
// 把store导入Pros
const mapStatetoProps = () => ({});

const mapDispatchtoProps = () => ({});
export default connect(
    mapStatetoProps,
    mapDispatchtoProps
)(RedirectContainer);
